package com.quasar.hpatient.view.personal.historyRecord;

import android.graphics.Color;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.quasar.hpatient.R;
import com.quasar.hpatient.base.BaseActivity;
import com.quasar.hpatient.model.custommodel.TestTable;
import com.quasar.hpatient.onInterface.viewInterface.UiInterface;
import com.quasar.hpatient.presenter.TestTablePresenter;
import com.quasar.hpatient.view.adapter.TestTableAdapter;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import java.util.List;

/**
 * 历史化验报告
 */
@EActivity(R.layout.activity_history_laboratory)
public class HistoryLaboratoryActivity extends BaseActivity implements BaseQuickAdapter.RequestLoadMoreListener, SwipeRefreshLayout.OnRefreshListener,UiInterface<List<TestTable>>{


    private TestTableAdapter testTableAdapter;
    private TestTablePresenter testTablePresenter;

    @ViewById(R.id.main_toolbar)
    Toolbar main_toolbar;
    @ViewById(R.id.swipeLayout)
    SwipeRefreshLayout swipeLayout;
    @ViewById(R.id.rv_list)
    RecyclerView rv_list;

    @AfterViews
    void init(){
        initView();
        initData();
    }

    @Override
    protected void initView() {
        initToolbar();
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setColorSchemeColors(Color.rgb(47, 223, 189));
        rv_list.setLayoutManager(new LinearLayoutManager(this));
    }

    //初始化adapter布局
    public void initAdapter(List<TestTable> data) {
        int size=data.size();
        testTableAdapter=new TestTableAdapter(R.layout.widget_test_show,R.layout.widget_test_edit_title,data);
        testTableAdapter.setOnLoadMoreListener(this, rv_list);
        testTableAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_LEFT);
        rv_list.setAdapter(testTableAdapter);
        //item点击
        rv_list.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(final BaseQuickAdapter adapter, final View view, final int position) {

            }
        });
    }

    @Override
    protected void initData() {
        testTablePresenter= new TestTablePresenter(this);
        testTablePresenter.PostAddFriend();
    }

    @Override
    public void onRefresh() {

    }

    @Override
    public void onLoadMoreRequested() {

    }

    @Override
    public void onViewSuccess(List<TestTable> data) {
        initAdapter(data);
    }

    @Override
    public void onViewError(String msg) {

    }

    @Override
    public void onViewRefreshUI() {
        testTableAdapter.notifyDataSetChanged();
    }
}
